<?php
/**
 * Note: 角色
 * Date: 2021/05/14
 */
namespace App\Models;

use App\Traits\ModelTrait;


class Role extends Base
{
    use ModelTrait;

    const STATUS_OFF = 0;
    const STATUS_ON = 1;

    public $timestamps = true;

    public $fillable = [
        'name',
        // 'access',
        'status',
        'sources',
        'creator_id'
    ];

    protected $casts = [
        'sources' => 'json',
    ];

    /**
     * 权限关联
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function roleAccess()
    {
        return $this->belongsToMany(\App\Models\RoleAccess::class, \App\Models\RolePermission::class, 'role_id', 'access_id');
    }


    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function creator()
    {
        return $this->hasOne(\App\Models\Manager::class, 'id', 'creator_id');
    }
}
